package demo1;

import java.util.List;

public class Queue {
    static class ListNode{
        public int val;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }
    public ListNode head;
    public ListNode last;
    public int usedSize;

    public void offer(int data){
        ListNode node = new ListNode(data);
        //入队列
        if(head == null){
            head = node;
            last = node;
        }else {
            last.next = node;
            last = last.next;
        }
        usedSize++;

    }

    public int getUsedSize(){
        return usedSize;
    }

   public  int poll(int data){
        ListNode node = new ListNode(data);
        if(head ==null){
            return -1;
        }
        if(head.next == null){
            int val = head.val;
            head = null;
            last = null;
            return val;
        }
        head = head.next;
        usedSize--;
        return -1;
   }
   public int peek(){
        if(head == null){
            return -1;
        }
        return head.val;
   }


}
